package mn.idax.exchange.otc.service;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class ClearCacheService {

    @Autowired
    private StringRedisTemplate redisTemplate;

    public LoadingCache<String, String> robotCache = CacheBuilder.newBuilder()
            .maximumSize(1)
            .refreshAfterWrite(1, TimeUnit.MINUTES)
            .build(new CacheLoader<String, String>() {
                @Override
                public String load(String robot) {
                    return redisTemplate.opsForValue().get(robot);
                }
            });

}
